/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


import java.io.IOException;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.Sprite;

/**
 *
 * @author ANH
 */
public class Ball {
    private int x;
    private int y;
    private int color;
    private int kind;
    private int curFrame;
    public int nMineAround;
    public boolean istouched;
    public boolean ishide;
    public boolean ismine;
    public boolean isdoubt;
    public boolean issure;
    private Sprite ball;
    private Sprite ball_sure;
    private Sprite ball_doubt;
    private Pointer p;
    public Ball(int _x,int _y,Sprite _ball,Sprite _ball_sure,Sprite _ball_doubt){
        istouched=false;
        x=_x;
        y=_y;
        nMineAround=0;
        ball=_ball;
        ball_sure=_ball_sure;
        ball_doubt=_ball_doubt;
        curFrame=0;
        p=null;
    }
   
     public void render(Graphics g) {
        int anchor = Graphics.TOP|Graphics.LEFT;
        ball.setPosition(x, y);
        if(istouched)    curFrame++;
        else curFrame=0;
        if(curFrame>15)
        {
            curFrame=0;
           
        }
        ball.setFrame(curFrame);

      if(!ishide)
      {
          if (issure)
          {
              ball_sure.setFrame(curFrame);
              ball_sure.setPosition(x, y);
              ball_sure.paint(g);
          }
          else if(isdoubt)
          {
              ball_doubt.setFrame(curFrame);
              ball_doubt.setPosition(x, y);
              ball_doubt.paint(g);
          }
          else ball.paint(g);
      }
     else
      {
          g.drawString(String.valueOf(nMineAround), x + 10, y + 5, anchor);
        //  if(istouched) p.render(g);
      }
    }
     private final Rectangle getArea() {
        return new Rectangle(x, y,25 , 25);
    }

    public final boolean isPressed(int x, int y) {
        return getArea().isPointInside(x, y);
    }
    private void CreateBall(){
        
    }
    public boolean OnSelelected(int x,int y){// dành cho chạm( tạm thời)
        if(isPressed(x,y))
        {
            if(!ishide) istouched=true;
          /*  else
            {
                istouched=true;
                p=new Pointer(this.x,this.y);
            }*/
            return true;
        }
        return false;
    }
    public void OnSelected(){// dành cho bấm phím (tạm thời)
        istouched = true;
    }
    public boolean Open()
    {
         if(ismine)
         {
            // isexplosed = true;
             return true;
        }
         else 
         {
             ishide=true;
             return false;
        }
    }
    public void setNoMineAround(int n){
        nMineAround=n;
        ishide=true;
    }
    public void reset()
    {
        ismine=false;
        ishide=false;
        istouched=false;
        curFrame=0;
        nMineAround=0;
    }
    public int getX(){
        return x;
    }
    public int getY(){
        return y;
    }
}
